package cn.ejiajunxy.manager;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.leo.baseui.tabview.TabsView;
import com.leo.baseui.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import cn.ejiajunxy.manager.fragment.FragmentOrderList;

/**
 * Created by zhangguobao on 2018/3/14.
 */

public class OrderActivity extends BaseActivity {
    private TabsView clTabs;
    private ViewPager vpContent;
    MainFragmentAdapter mAdapter;
    private List<String> mTitle;

    @Override
    protected void init() {
        assignViews();
    }

    private void assignViews() {
        mTitle = new ArrayList<>();
        mTitle.add("未送订单");
        mTitle.add("已送订单");
        clTabs = (TabsView) findViewById(R.id.clTabs);
        vpContent = (ViewPager) findViewById(R.id.vpContent);
        mAdapter = new MainFragmentAdapter(getSupportFragmentManager());
        vpContent.setAdapter(mAdapter);
        vpContent.setCurrentItem(0);
        clTabs.notifyDataChanged(mTitle, 0);
        clTabs.setupWithViewPager(vpContent);
        clTabs.setOnItemSelectListener(new TabsView.OnItemSelectListener() {
            @Override
            public void onSelect(int position, String title) {
                vpContent.setCurrentItem(position);
            }
        });
    }


    public static void start(Context context) {
        Intent starter = new Intent(context, OrderActivity.class);
        context.startActivity(starter);
    }


    private class MainFragmentAdapter extends FragmentPagerAdapter {
        public MainFragmentAdapter(FragmentManager fm) {
            super(fm);
        }


        @Override
        public Fragment getItem(int position) {
            return FragmentOrderList.newInstance(position);
        }

        @Override
        public int getCount() {
            return 2;
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_order;
    }
}
